<template>
  <div class="reportMistakeInfoAction el-card is-always-shadow el-card__body">
      <!--非长周期车站密码确认-->
      <el-dialog title="账户密码确认" :visible="dialogVisibleAccountPassword" :gutter="24" @close="dialogVisibleAccountPassword=false" :modal-append-to-body="false" :append-to-body="true" width="400px">
        <el-form :model="accountParamForm"  ref="accountPassword" label-width="100px" class="accountPassword-ruleForm" v-if="dialogVisibleAccountPassword">
          <el-form-item label="账户：" prop="name">
            <el-input v-model="accountParamForm.account"></el-input>
          </el-form-item>
          <el-form-item label="密码：" prop="name">
            <el-input type="password" v-model="accountParamForm.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" :loading="loading" @click="checkAccount()">确认</el-button>
            <el-button @click="dialogVisibleAccountPassword=false">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
      <!--长周期车站密码确认-->
      <el-dialog title="账户密码确认" :visible="dialogVisibleLongPeriod" :gutter="24" @close="dialogVisibleLongPeriod=false" :modal-append-to-body="false" :append-to-body="true" width="400px">
        <el-form :model="accountParamForm"  ref="accountPassword" label-width="100px" class="accountPassword-ruleForm" v-if="dialogVisibleLongPeriod">
          <el-form-item label="账户：" prop="name">
            <el-input v-model="accountParamForm.account"></el-input>
          </el-form-item>
          <el-form-item label="密码：" prop="name">
            <el-input type="password" v-model="accountParamForm.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="checkAffirm()">确认</el-button>
            <el-button @click="dialogVisibleLongPeriod=false">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
  </div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import ExportJsonExcel from "js-export-excel";
    import moment from 'moment';
    import {checkAccountPassword} from "../../../api/subwayRat/commonCheck";
    export default {
      components:{
      },
      data() {
            return {
              dialogVisibleAccountPassword:false,
              dialogVisibleLongPeriod:false,
              accountParamForm:{
                account:'',
                password:'',
                token:''
              },
              allowClickSubmit:false,
              loading: false,
            }
        },
        created() {

        },
        props:['params'],
        methods: {
          moment,
          checkAccount(){//检测密码
            // this.accountParamForm.roleCode='ZBZZ';
            // this.accountParamForm.isCheckRole=true;
            Object.assign(this.accountParamForm,this.params);
            checkAccountPassword(this.accountParamForm).then(res=>{
              if(res.data.code==0 && res.data.data){
                  this.loading = true;
                  this.$message.success('验证成功!');
                  this.$emit("checkSubmitSuccess",this.accountParamForm.account, //由父组件调用
                  (response)=> {
                    if(response.data.code==0){
                      this.$message.success("提交成功!");
                      this.loading = false;
                      this.dialogVisibleAccountPassword=false;
                    }else{
                      this.$message.error("提交失败!");
                      this.loading = false;
                      this.dialogVisibleAccountPassword=false;
                    }
                  }, 
                  (error)=> {
                      if(error.message.indexOf('timeout')!=-1){
                        this.$message.warning('提交操作需要一定时间，稍后进行查看，请勿重复提交!')
                        this.loading = false;
                        this.dialogVisibleAccountPassword=false;
                      }else{
                        this.$message.error("提交失败,请重新尝试!");
                        this.loading = false;
                        this.dialogVisibleAccountPassword=false;
                      }
                  });
              }else{
                this.$message.error("验证失败!");
              }
            })
          },
          checkAffirm(){//检测密码
            Object.assign(this.accountParamForm,this.params);
            checkAccountPassword(this.accountParamForm).then(res=>{
              if(res.data.code==0 && res.data.data){
                  this.$message.success('验证成功!');
                  this.dialogVisibleLongPeriod=false;
                  this.$emit("checkSubmitSuccess",this.accountParamForm.account);
              }else{
                this.$message.error("验证失败!");
              }
            })
          }
        },
      mounted() {
      }
    }
</script>
<style lang="scss">

</style>
